home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / REALITY / atom / texture.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.8 KB  |  158 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "gl.h"
  18. #include "image.h"
  19.  
  20. static int firsted = 0;
  21.  
  22.  
  23. textureread(name,texno, filter_type)
  24.     char *name;
  25.     int texno, filter_type;
  26. {
  27.     unsigned long *imagedata;
  28.     int i;
  29.     static float texps0[] = { TX_NULL };
  30.     static float texps1[] = { TX_MINFILTER, TX_MIPMAP_POINT, 
  31.                    TX_MAGFILTER, TX_POINT, 
  32.                    TX_NULL };
  33.     static float texps2[] = { TX_MINFILTER, TX_MIPMAP_BILINEAR, 
  34.                    TX_MAGFILTER, TX_BILINEAR, 
  35.                    TX_NULL };
  36.     static float texps3[] = { TX_MINFILTER, TX_BILINEAR, 
  37.                    TX_MAGFILTER, TX_BILINEAR, 
  38.                    TX_NULL };
  39.     static float texps4[] = { TX_MINFILTER, TX_MIPMAP_LINEAR, 
  40.                    TX_MAGFILTER, TX_BILINEAR, 
  41.                    TX_NULL };
  42.     static float tevps[] = { TV_NULL };
  43.  
  44.     imagedata = (unsigned long *)longimagedata(name);
  45.  
  46.     /*
  47.     printf(" defining texture: %d\n", texno);
  48.     */
  49.  
  50.     switch (filter_type) {
  51.     case 0:
  52.     texdef2d(texno,4,128,128,imagedata,0,texps0);
  53.     break;
  54.     case 1:
  55.     texdef2d(texno,4,128,128,imagedata,0,texps1);
  56.     break;
  57.     case 2:
  58.     texdef2d(texno,4,128,128,imagedata,0,texps2);
  59.     break;
  60.     case 3:
  61.     texdef2d(texno,4,128,128,imagedata,0,texps3);
  62.     break;
  63.     case 4:
  64.     texdef2d(texno,4,128,128,imagedata,0,texps0);
  65.     break;
  66.     }
  67.     if(!firsted) {
  68.        tevdef(1,0,tevps);
  69.        tevbind(0,1);
  70.        firsted = 1;
  71.     }
  72. }
  73.  
  74. textureread1(name,texno, filter_type)
  75.     char *name;
  76.     int texno, filter_type;
  77. {
  78.     long *imagedata;
  79.     short *tmp;
  80.     int i,j;
  81.     static float texps0[] = { TX_NULL };
  82.     static float texps1[] = { TX_MINFILTER, TX_MIPMAP_POINT, 
  83.                    TX_MAGFILTER, TX_POINT, 
  84.                    TX_NULL };
  85.     static float texps2[] = { TX_MINFILTER, TX_MIPMAP_BILINEAR, 
  86.                    TX_MAGFILTER, TX_BILINEAR, 
  87.                    TX_NULL };
  88.     static float texps3[] = { TX_MINFILTER, TX_BILINEAR, 
  89.                    TX_MAGFILTER, TX_BILINEAR, 
  90.                    TX_NULL };
  91.     static float texps4[] = { TX_MINFILTER, TX_MIPMAP_LINEAR, 
  92.                    TX_MAGFILTER, TX_BILINEAR, 
  93.                    TX_NULL };
  94.     static float tevps[] = { TV_BLEND, TV_COLOR, 0.65, 0.65, 0.60, 1.0,
  95.                  TV_NULL };
  96.  
  97.     imagedata = (char *)charimagedata(name);
  98.     for (i=0; i < 128*32; i++) {
  99.     /*
  100.             tmp = (short *)(imagedata + i);
  101.         *(tmp ) = (short) (((*tmp)/255.) * ((*tmp)/255.)) *255.*255.;
  102.         *(tmp +1) = *(tmp +1);
  103.     */
  104.     imagedata[i] = ~imagedata[i];
  105.     }
  106.  
  107.     /*
  108.     printf(" defining texture: %d\n", texno);
  109.     */
  110.  
  111.     switch (filter_type) {
  112.     case 0:
  113.     texdef2d(texno,1,128,128,imagedata,0,texps0);
  114.     break;
  115.     case 1:
  116.     texdef2d(texno,1,128,128,imagedata,0,texps1);
  117.     break;
  118.     case 2:
  119.     texdef2d(texno,1,128,128,imagedata,0,texps2);
  120.     break;
  121.     case 3:
  122.     texdef2d(texno,1,128,128,imagedata,0,texps3);
  123.     break;
  124.     case 4:
  125.     texdef2d(texno,1,128,128,imagedata,0,texps0);
  126.     break;
  127.     }
  128.     if(!firsted) {
  129.        tevdef(1,0,tevps);
  130.        tevbind(0,1);
  131.        firsted = 1;
  132.     }
  133. }
  134.  
  135. static curtexture = 0;
  136. settexture(n)
  137. int n;
  138. {
  139.     if (n == curtexture)
  140.       return;
  141.     texbind(TX_TEXTURE_0,n);
  142.     curtexture = n;
  143. }
  144.  
  145. #define ENVSCALE 2.15
  146.  
  147. float stexgen(vert) 
  148.      float vert[3];
  149. {
  150.      return ((vert[0] / ENVSCALE) + 0.5);
  151. }
  152.  
  153. float ttexgen(vert) 
  154.      float vert[3];
  155. {
  156.       return ((vert[1] / ENVSCALE) + 0.5);
  157. }
  158.